import { reqGetSearchInfo } from "@/api/index"

//search模块小仓库
const state = {
    searchList:{}
}
const mutations = {
    GETSEARCHLIST(state,searchList){
        state.searchList = searchList
    }
}
const actions = {
    async getSearchList({commit},params={}) {
        //至少传递一个空对象
        //params形参是当dispatch第二个参数传递过来的
       let result = await reqGetSearchInfo(params)
       if (result.code === 200) {
        commit("GETSEARCHLIST",result.data)
       }
    }
}
// 计算属性，为了简化数据
//可以把将来组件中用的数据简化，组件获取数据方便
const getters = {
    //当前形参state,当前仓库中的state，并非大仓库中的state
    goodsList(state){
        //加入没有网，返回的是undefined
        return state.searchList.goodsList || [];
    },
    trademarkList(state){
        return state.searchList.trademarkList || [];
    },
    attrsList(state){
        return state.searchList.attrsList || [];
    }
}

export default {
    state,
    mutations,
    actions,
    getters
}